package com.JavaNet.chapter7_urlConnection;

import java.io.*;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

/**
 * @author 吴世凯
 *         邮箱：
 *         日期：4/21/2021
 */
public class JarConnectionDemo {


    public static void main(String[] args) throws IOException {

        readFile();


    }


    public static void readFile( ) throws FileNotFoundException, MalformedURLException {


        URL url = new URL("file://d:/pom.xml");  //本地文件协议
        File file = new File(url.getFile());

//        File file = new File("D:\\pom.xml");

        InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file));


        char[] cs = new char[64];
        int index = 0;

        while (index >= 0) {
            try {

                index = inputStreamReader.read(cs, 0, cs.length);   //这个批次从0 开始读取, 读满这个数组为止;
                PrintWriter printWriter = new PrintWriter(System.out);
                printWriter.print(cs);
                printWriter.flush();
            } catch (Exception e) {
                System.out.println("cs:" + Arrays.toString(cs));
                System.out.println("index:" + index);
                e.printStackTrace();
                return;
            }


        }
        System.out.println();
        System.out.println("文件读取完毕.....");


    }

    public static void readJar( ) throws IOException {

        String urlString = "http://butterfly.jenkov.com/"
                + "container/download/"
                + "jenkov-butterfly-container-2.9.9-beta.jar";

        URL jarUrl = new URL(urlString);
        JarURLConnection connection = new JarURLConnection(jarUrl) {
            @Override
            public void connect( ) throws IOException {

            }

            @Override
            public JarFile getJarFile( ) throws IOException {
                return null;
            }
        };



        /*manifest  很熟悉, 但是又不知道怎么用 */
        Manifest manifest = connection.getManifest();

        JarFile jarFile = connection.getJarFile();

    }
}
